from flask import Flask, request, jsonify

app = Flask(__name__)


@app.route('/headers', methods=['GET', 'POST'])
def show_headers():
    # 获取所有请求头信息
    headers = dict(request.headers)

    # 打印到控制台
    print("\nReceived Headers:")
    for key, value in headers.items():
        print(f"{key}: {value}")

    # 返回JSON格式的头信息
    return jsonify(headers)


if __name__ == '__main__':
    app.run(debug=True)